<?php
namespace common\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "game_beta".
 *
 * @property string $id
 * @property string $game_id
 * @property string $game_name
 * @property string $game_url
 * @property string $beta_time
 * @property integer $end_time
 * @property integer $beta_type
 * @property string $game_state
 * @property integer $game_type_id
 * @property string $game_type
 * @property string $area_name
 * @property string $beta_detail
 * @property string $create_time
 * @property string $update_time
 * @property string $display_site
 */
class GameBeta extends \yii\db\ActiveRecord
{

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'game_beta';
    }

    /*
     * 产生创建日期和更新日期时间戳
     */
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'createdAtAttribute' => 'create_time',
                'updatedAtAttribute' => 'update_time'
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [
                [
                    'game_id',
                    'beta_time',
                    'end_time',
                    'beta_type',
                    'game_type_id',
                    'create_time',
                    'update_time'
                ],
                'integer'
            ],
            [
                [
                    'game_name',
                    'game_id',
                    'game_url',
                    'beta_type',
                    'area_name',
                    'beta_detail'
                ],
                'required'
            ],
            [
                [
                    'beta_detail'
                ],
                'string'
            ],
            [
                [
                    'game_name',
                    'game_state',
                    'game_type'
                ],
                'string',
                'max' => 100
            ],
            [
                [
                    'game_url'
                ],
                'string',
                'max' => 255
            ],
            [
                [
                    'area_name',
                    'display_site'
                ],
                'string',
                'max' => 50
            ],
            [
                'game_url',
                'match',
                'pattern' => "/\b(?:(?:https?):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",
                'message' => '链接URL不是一个有效的URL.'
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'game_id' => '游戏ID',
            'game_name' => '游戏名称',
            'game_url' => '链接URL',
            'beta_time' => '开测时间',
            'end_time' => '结束时间',
            'beta_type' => '测试类型',
            'game_state' => '游戏状态',
            'game_type_id' => '游戏类型ID',
            'game_type' => '游戏类型',
            'area_name' => '新区名称',
            'beta_detail' => '开测介绍',
            'create_time' => '创建时间',
            'update_time' => '更新时间',
            'display_site' => '显示位置'
        ];
    }

    // relationship
    /**
     * 所属游戏
     */
    public function getGame()
    {
        return $this->hasOne(Game::className(), [
            'game_id' => 'game_id'
        ]);
    }

    /**
     * 所属游戏信息
     */
    public function getGameInfo()
    {
        return $this->hasOne(GameInfo::className(), [
            'game_id' => 'game_id'
        ]);
    }
}
